home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 3: The Continuation / 17-Bit_The_Continuation_Disc.iso / amigan / amigan 12 / memfree.asm < prev    next >
Assembly Source File  |  1994-01-27  |  5KB  |  174 lines

  1. * FreeMem.a:    An assembler free memory lister.  I came up with this
  2. *        as a quicker way to get free ram than 'avail.'
  3. *
  4. * Author:
  5. *        James E. Cooper Jr.
  6. *        113 Collier Pl.  Apt 1B
  7. *        Cary, NC  27513
  8. *
  9. * Notes:
  10. *        First working version. 3/1/87  jec
  11. *        Modified to handle FAST RAM. 4/6/87  jec
  12. *        Added RawDoFmt call, instead of bindec and ldiv,
  13. *            giving FASTER operation, and SMALLER code.
  14. *            Many, MANY thanks to Joe Bostic of THE
  15. *            AMIGAN for documenting this call!!!
  16. *            (See AMIGAN, Vol II, #3)  8/22/87  jec
  17. *        Added dynamic variable allocation, so you can make
  18. *            it resident, if anyone ever figures out how!
  19. *            8/23/87  jec
  20. *        Added largest hunk report.  8/23/87  jec
  21. *
  22. * Included equate files.
  23. * -----------------------------------------------------------------------
  24. *    NOLIST
  25.     INCLUDE "exec/types.i"
  26.     INCLUDE "exec/libraries.i"
  27.     INCLUDE "exec/memory.i"
  28.     INCLUDE "libraries/dos.i"
  29. *    LIST
  30.  
  31. * External references
  32.  
  33. * DOS offsets
  34. * -----------------------------------------------------------------------
  35. Write        EQU    -48        ; ((-5*6)+(-18)) (from RKM)
  36. Output        EQU    -60        ; ((-5*6)+(-30))
  37.  
  38. * Exec offsets
  39. * -----------------------------------------------------------------------
  40. ExeBase     EQU    4
  41. Forbid        EQU    -132        ; ((-5*6)+(-102))
  42. Permit        EQU    -138        ; ((-5*6)+(-108))
  43. AllocMem    EQU    -198        ; ((-5*6)+(-168))
  44. FreeMem     EQU    -210        ; ((-5*6)+(-180))
  45. AvailMem    EQU    -216        ; ((-5*6)+(-186))
  46. OpenLibrary    EQU    -408        ; ((-5*6)+(-378))
  47. RawDoFmt    EQU    -522        ; ((-5*6)+(-492))
  48.  
  49. * Local Equates
  50. * ------------------------------------------------------------------------
  51. TRUE    EQU    -1
  52. FALSE    EQU    0
  53.  
  54. * A structure definition
  55. * -------------------------------------------------------------------------
  56.  
  57.     STRUCTURE    Variables,0
  58.     LONG    v_CHIP        ; storage for free chip parm
  59.     LONG    v_LCHIP     ;    "     "   "    "   largest hunk
  60.     LONG    v_FAST        ;    "     "   "   fast parm
  61.     LONG    v_LFAST     ;    "     "   "    "   largest hunk
  62.     LONG    v_TOTAL     ;    "     "   "   total parm
  63.     STRUCT    v_OUTPUT,96    ; storage for output string
  64.     LABEL    v_SIZEOF
  65.  
  66. * The code segment
  67. * -------------------------------------------------------------------------
  68.  
  69.     moveq    #0,d0
  70.  
  71.     ;------ get Exec's library base pointer:
  72.     LEA.L    DOSName(PC),A1        ; name of dos library
  73.     move.l    #LIBRARY_VERSION,d0
  74.  
  75.     move.l    a0,a5            ; save A0 for later use
  76.     move.l    ExeBase,a6
  77.     jsr    OpenLibrary(a6)
  78.     MOVE.L    D0,-(a7)        ; Save library pointer on stack
  79.     BNE.S    gotdos
  80.  
  81.     ; Should really issue an alert here...
  82.     moveq    #RETURN_FAIL,D0     ; give up
  83.     bra    FINISHED
  84.  
  85. gotdos:
  86. *
  87. *    ; REGISTER USAGE:
  88. *    ;    A0,A1,A2= scratch
  89. *    ;    A3    = pointer to output string area, for store routine
  90. *    ;    A4    = pointer to variable storage
  91. *    ;    A6    = dos library base pointer
  92. *    ;    D1-3    = AmigaDOS scratch argument registers
  93. *    ;    D5    = output handle
  94. *
  95. *    Allocmem some variable space, so we can be resident
  96.     move.l    #v_SIZEOF,d0        ; size of the block
  97.     move.l    #MEMF_PUBLIC,d1     ; memory type requirement
  98.     movem.l d2-d7/a0-a6,-(sp)    ; save to avoid trashing
  99.     jsr    AllocMem(a6)        ; get some
  100.     movem.l (sp)+,d2-d7/a0-a6    ; restore registers
  101.     move.l    d0,a4            ; store away for later
  102. *    Obtain the output handle (needed for write)
  103.     move.l    (a7),a6           ; get DOSBase
  104.     jsr    Output(a6)
  105.     MOVE.L    D0,D5            ; Save for the write
  106.     move.l    ExeBase,a6
  107.     jsr    Forbid(a6)        ; don't let 'em change while we ask
  108.     move.l    #MEMF_CHIP,d1        ; ok, check free chip
  109.     jsr    AvailMem(a6)
  110.     move.l    d0,v_CHIP(a4)        ; store in parms table
  111.     move.l    #MEMF_CHIP|MEMF_LARGEST,d1 ; to find largest hunk in chip ram
  112.     jsr    AvailMem(a6)
  113.     move.l    d0,v_LCHIP(a4)
  114.     move.l    #MEMF_FAST,d1        ; check free fast
  115.     jsr    AvailMem(a6)
  116.     move.l    d0,v_FAST(a4)        ; store in parms table
  117.     move.l    #MEMF_FAST|MEMF_LARGEST,d1 ; to find largest hunk in fast ram
  118.     jsr    AvailMem(a6)
  119.     move.l    d0,v_LFAST(a4)
  120.     move.l    #MEMF_PUBLIC,d1     ; get all available memory
  121.     jsr    AvailMem(a6)        ; ask system how much there is
  122.     move.l    d0,v_TOTAL(a4)        ; store in parms table
  123.     jsr    Permit(a6)        ; done - they can load all they want
  124.     lea    MEMORY,a0        ; load format string
  125.     movea.l a4,a1            ;   pieces
  126.     lea    store,a2        ; routine that puts chars in output
  127.     move.l    a4,d0            ; where to put 'em
  128.     add.l    #v_OUTPUT,d0        ; adjust
  129.     move.l    d0,a3            ; and put it where RawDoFmt needs it
  130.     move.l    a3,a5            ; also, save it for PRINT
  131.     jsr    RawDoFmt(a6)        ; have system 'make' output string
  132.     move.l    d5,d1            ; Output file handle
  133.     move.l    a5,d2            ; pointer to buffer
  134.     moveq    #v_SIZEOF,d0        ; convenient count
  135.     moveq    #0,d3            ; init char count
  136. lenloop:
  137.     cmpi.b    #0,(a5)+        ; NULL yet?
  138.     beq.s    printit         ; yes, goforit!
  139.     addq.l    #1,d3            ; increment char count
  140.     dbra    d0,lenloop        ; and check again
  141. printit:
  142.     move.l    (a7),a6         ; get DOSBase for call
  143.     jsr    Write(a6)        ; and print it all out!
  144.     move.l    a4,a1            ; set up for _LVOFreeMem
  145.     move.l    #v_SIZEOF,d0        ; size to free
  146.     move.l    ExeBase,a6
  147.     jsr    FreeMem(a6)
  148.     move.l    #RETURN_OK,D0
  149. FINISHED:
  150.     addq    #4,a7            ; adjust stack for exit
  151.     rts
  152.  
  153. * Subroutines
  154. * ------------------------------------------------------------------------
  155. ********************************************************************************
  156. * STORE:    routine used by _LVORawDoFmt to store output string
  157. ********************************************************************************
  158.  
  159. store:
  160.     move.b    d0,(a3)+
  161.     rts
  162.  
  163. ********************************************************************************
  164. * Data declarations
  165. ********************************************************************************
  166.  
  167.     CNOP    0,4
  168. DOSName     DOSNAME
  169. MEMORY        DC.B    'Chip: %ld, largest %ld',10
  170.         DC.B    'Fast: %ld, largest %ld',10
  171.         DC.B    'Free memory: %ld bytes.',10,0
  172.     END
  173.  
  174.